#/bin/bash

MACHINE_TYPE=`uname -m`
mkdir -p ../Linux/
INSTALL_DIR=`readlink -f ../Linux/`/
declare -a arr=(Debug Release)
declare -a arr2=("--enable-debug-runtime=yes" "--enable-optimized=yes --enable-assertions=no")
for i in {0..1}
do
    d=${arr[$i]}
    c=${arr2[$i]}
    
    if [ ${MACHINE_TYPE} == 'x86_64' ]; then
        mkdir -p ${INSTALL_DIR}x86_64/$d
        mkdir -p x86_64/$d
        cd x86_64/$d
        $1/configure --enable-terminfo=no --enable-zlib=no --prefix=${INSTALL_DIR}x86_64/$d --enable-targets=host $c
        make -j16
        make install
        cd ../../
        mkdir -p ${INSTALL_DIR}x86/$d
        mkdir -p x86/$d
        cd x86/$d
        CC='gcc -m32' CXX='g++ -m32' LD='ld -m32' $1/configure --enable-terminfo=no --enable-zlib=no --prefix=${INSTALL_DIR}x86/$d --host=i386-pc-linux-gnu --build=i686-pc-linux-gnu --enable-targets=host $c
        CC='gcc -m32' CXX='g++ -m32' LD='ld -m32' make -j16
        make install
        cd ../../
    else
        mkdir -p ${INSTALL_DIR}x86/$d
        mkdir -p x86/$d
        cd x86/$d
        $1/configure --enable-terminfo=no --enable-zlib=no --prefix=${INSTALL_DIR}x86/$d --enable-targets=host $c
        make -j16
        make install
        cd ../../
    fi
done
